<template>
  <div class="app-container">
    <div class="default-box">
      <div class="filter-container">
        <el-button class="filter-item" type="primary" icon="el-icon-plus" round @click="createDialog = true;isadd = true">
          新增
        </el-button>
      </div>
      <el-table
        :key="tableKey"
        v-loading="listLoading"
        :data="list"
        fit
        highlight-current-row
        style="width: 100%;"
      >
        <el-table-column label="平台" width="180">
          <template>
            <span>阿里云</span>
          </template>
        </el-table-column>
        <el-table-column label="版本" width="180">
          <template>
            <span>1.00.04</span>
          </template>
        </el-table-column>
        <el-table-column label="升级内容" min-width="150" show-overflow-tooltip>
          <template>
            <span>升级升级升级升级升级升级升级升级升级升级升级升级升级升级升级升级升级升级</span>
          </template>
        </el-table-column>
        <el-table-column label="状态" width="200">
          <template>
            <el-switch v-model="status" active-text="启用" inactive-text="禁用" />
          </template>
        </el-table-column>
        <el-table-column label="创建时间" width="200">
          <template>
            <span>
              2023-03-15 17:25:28
            </span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200" class-name="small-padding fixed-width">
          <template>
            <i class="el-icon-edit" :style="{color:$store.state.settings.theme}" @click="createDialog = true;isadd = false" />
            <i class="el-icon-delete danger-color" @click="handleDelete" />
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    </div>
    <!-- 展示新增对话框 -->
    <el-dialog
      :title="isadd?'新增版本控制':'编辑版本控制'"
      :visible.sync="createDialog"
      width="50%"
      custom-class="operate-dialog"
      top="20vh"
      center
    >
      <el-form :model="oprateform" label-width="150px">
        <el-form-item label="类型">
          <el-select v-model="statusvalue" filterable placeholder="请选择类型" class="fullwidth">
            <el-option v-for="item in statusoptions" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="版本">
          <el-input v-model="oprateform.name" placeholder="请输入版本" />
        </el-form-item>
        <el-form-item label="全量包地址">
          <el-input v-model="oprateform.name" placeholder="Apk安装包地址，或苹果商店地址" />
        </el-form-item>
        <el-form-item label="1.00.07增量包地址">
          <el-input v-model="oprateform.name" placeholder="1.00.08增量包地址" />
        </el-form-item>
        <el-form-item label="1.00.06增量包地址">
          <el-input v-model="oprateform.name" placeholder="1.00.07增量包地址" />
        </el-form-item>
        <el-form-item label="热更新地址">
          <el-input v-model="oprateform.name" placeholder="Wgt文件地址" />
        </el-form-item>
        <el-form-item label="灰度发布用户ID">
          <el-input v-model="oprateform.name" placeholder="灰度发布用户ID，多个用户用逗号分隔" />
        </el-form-item>
        <el-form-item label="更新内容">
          <el-input v-model="oprateform.describe" type="textarea" :autosize="{ minRows: 5, maxRows: 5}" placeholder="请填写更新内容" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleResetOperate">重置</el-button>
        <el-button type="primary" @click="handleOperate">提交</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { fetchList } from '@/api/article'
import Pagination from '@/components/Pagination'
export default {
  name: 'Adminrole',
  components: { Pagination },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10,
        title: ''
      },
      status: true,
      statusoptions: [{ // 状态选择项组
        value: '苹果',
        label: '苹果'
      }, {
        value: '安卓',
        label: '安卓'
      }],
      statusvalue: '', // 状态的类型
      oprateform: { // 新增、编辑条件
        name: '',
        describe: ''
      },
      isadd: true, // 是新增 否编辑
      createDialog: false // 是否展示新增、编辑对话框
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      fetchList(this.listQuery).then(response => {
        this.list = response.data.items
        this.total = response.data.total
        setTimeout(() => {
          this.listLoading = false
        }, 1.5 * 1000)
      })
    },
    // 新增、编辑
    handleOperate() {
      this.createDialog = false
    },
    // 重置新增、编辑支付宝支付配置输入框
    handleResetOperate() {
      this.oprateform.name = ''
      this.oprateform.describe = ''
    },
    // 删除
    handleDelete(row, index) {
      this.$confirm('确定要删除该记录吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        center: true,
        customClass: 'text-center'
      }).then(() => {
        this.$notify({
          title: '成功',
          message: '删除成功',
          type: 'success',
          duration: 2000
        })
        // this.$message({
        //   type: 'success',
        //   message: '删除成功!'
        // })
      }).catch(() => {

      })
      this.list.splice(index, 1)
    }
  }
}
</script>
<style scoped>
  [class^=el-icon-], [class*=" el-icon-"]{
    font-size: 16px;
  }
  .small-padding i{
    margin-right: 12px;
  }
  .small-padding i:last-child{
    margin-right: 0px;
  }
</style>
